package com.xwltz.repository.impl;

import com.xwltz.model.Student;
import com.xwltz.repository.StudentRepository;
import org.springframework.stereotype.Repository;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

@Repository
public class StudentRepositoryImpl implements StudentRepository {
    public static Map<Long, Student> studentMap;

    static {
        studentMap = new HashMap<>();
        studentMap.put(1l, new Student(1L, "我是a", 11));
        studentMap.put(2l, new Student(2L, "我是b", 12));
        studentMap.put(3l, new Student(3L, "我是c", 13));
    }

    @Override
    public Collection<Student> finAll() {
        return studentMap.values();
    }

    @Override
    public Student findById(long id) {
        return studentMap.get(id);
    }

    @Override
    public boolean saveOrUpdate(Student student) {
        studentMap.put(student.getId(), student);
        return true;
    }

    @Override
    public boolean deleteById(long id) {
        studentMap.remove(id);
        return true;
    }
}
